﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using ExtAspNet;
using FJASPX.Framwork.UI;
using FJASPX.Framwork.Helper;
using FJASPX.Framwork.Constant;
using FJASPX.Service;
using log4net;

namespace PlugNT.Cms.Web.Member.Setting
{
    public partial class CompanyInfo : EditPageBase<FJASPX.Domain.Enterprise>
    {
        #region Property属性

        public IEnterpriseService iEnterpriseService { get; set; }

        public IUserService iUserService { get; set; }

        public FJASPX.Domain.User User { get; set; }

        public override string PowerCode
        {
            get { throw new NotImplementedException(); }
        }
        #endregion
        #region Methods方法

        protected override bool FirstCallRead()
        {
            //初始化控件
            base.FirstCallRead();
            this.IsUpdate = true;
            this.ddl_CompanyType.Items.Add(new ListItem("--请选择--", "0"));
            this.ddl_Area.Items.Add(new ListItem("--请选择--", "0"));
            FJASPX.Domain.User user = iUserService.GetUserByName(this.CurrentUser.UserName);
            if (!user.IsNull())
            {
                this.Model = iEnterpriseService.GetByUser(user);
                if (!this.Model.IsNull())
                {
                    this.txt_Name.SetValue(this.Model.Name);
                    this.txt_Info.SetValue(this.Model.Description);
                    this.dd_Count.SetValue(this.Model.Scale);
                    this.txt_Fax.SetValue(this.Model.Fax);
                    this.txt_Mobile.SetValue(this.Model.Mobile);
                    this.txt_QQ.SetValue(this.Model.QQ);
                    this.txt_Telphone.SetValue(this.Model.Telphone);
                    this.txt_file.SetValue(this.Model.Logo);
                    if (!this.Model.Logo.IsEmpty())
                    {
                        this.img_PicD.Src = this.Model.Logo.GetResolvedUrl();
                    }

                }
            }
            return true;
        }
        #endregion

        #region Events事件
        protected void btn_Submit_Click(object sender, EventArgs e)
        {
            FJASPX.Domain.User user = iUserService.GetUserByName(this.CurrentUser.UserName);
            this.Model = iEnterpriseService.GetByUser(user);
            try
            {
                if (this.Model.IsNull())
                {
                    this.Model = new FJASPX.Domain.Enterprise();
                    this.Model.User = user;
                }
                this.Model.Name = this.txt_Name.GetValue();
                this.Model.Logo = this.SavePic(this.Model.Logo, this.txt_file.GetValue(), Cfg.USERPIC_PAGE_PATH);
                this.Model.Description = this.txt_Info.GetValue();
                this.Model.Scale = this.dd_Count.GetValue();
                this.Model.Telphone = this.txt_Telphone.GetValue();
                this.Model.Mobile = this.txt_Mobile.GetValue();
                this.Model.QQ = this.txt_QQ.GetValue();
                this.Model.Fax = this.txt_Fax.GetValue();

                iEnterpriseService.Save(this.Model);
                this.Success(); //这里加清缓存操作
                return;
            }
            catch (Exception ex)
            {
                Log.WriteLog(Message.ERR, ex);
            }
            this.Fail();
        }
        #endregion
    }
}